package cn.com.gridinfo.sooc.core.my.personal.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.jeremy.arad.utils.AnimUtil;
import com.jeremy.arad.utils.Log;
import com.jeremy.arad.utils.StringUtils;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import cn.com.gridinfo.sooc.R;
import cn.com.gridinfo.sooc.base.BaseSoocActivity;
import cn.com.gridinfo.sooc.core.my.msg.activity.MsgActivity;
import cn.com.gridinfo.sooc.utils.IntentUtil;

/**
 * 已经绑定的手机号
 * Created by liuxiaochen on 2015/12/21.
 */
public class OnBoundCellNumberActivity extends BaseSoocActivity {
    @InjectView(R.id.cellphone)//已绑定的手机号
    TextView cellphone;
    @InjectView(R.id.btn_next)// 点击 下一步按钮
    Button btnNext;
    private String cellNumber;//全局拿到已绑定的手机号
    private String showNumber;
    public static OnBoundCellNumberActivity instance;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_onbound_cellnumber);
        ButterKnife.inject(this);
        instance = this;
        cellNumber=getIntent().getStringExtra("cellphone");//拿到上个界面传来的手机号
        Log.d("已绑定的手机号"+cellNumber);
        initView();//初始化数据
        cellphone.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        cellphone.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_NEXT) {
                    if(validateNotNull()){
                        next();
                    }

                }
                return false;
            }
        });

    }
    private boolean validateNotNull(){
        //账号为空
        if(StringUtils.isNull(cellphone.getText().toString().trim())){
            cellphone.requestFocus();
            return false;
        }
        return true;
    }
    //初始化显示手机号
    private void initView() {
//        String beforePhone = cellNumber.substring(0, 3);//拿到电话号码前3位
//        String afterPhone = cellNumber.substring(7, 11);//拿到电话号码的后4位
//        showNumber=beforePhone + "****" + afterPhone;
        cellphone.setText(cellNumber);
    }
    //设置标题
    @Override
    public String setupToolBarTitle() {
        return "绑定手机号";
    }
    //设置左边按钮
    @Override
    public boolean setupToolBarLeftButton(ImageView leftButton) {
        return true;
    }
    //返回
    @OnClick(R.id.toolbar_leftbtn)
    void onGoBack() {
        finish();
    }
    //下一步按钮
    @OnClick(R.id.btn_next)
    void next() {
        startActivity(new Intent(this, ChangeCellNumberActivity.class));
        AnimUtil.intentSlidIn(this);
    }
}
